home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / STONED / MBOOT.ZIP / MBOOT.ASM next >
Encoding:
Assembly Source File  |  1995-04-26  |  2.7 KB  |  106 lines

  1. ;A Master Boot Record
  2. ;(C) 1995 American Eagle Publications, Inc., All Rights Reserved.
  3.  
  4. .model tiny
  5. .code
  6.  
  7. ;The loader is executed when this program is run from the DOS prompt. It
  8. ;reads the partition table and installs the Master Boot Sector to the C: drive.
  9.  
  10.         ORG     100H
  11.  
  12. LOADER:
  13.         mov     ax,201H         ;read existing master boot sector
  14.         mov     bx,OFFSET BUF
  15.         mov     cx,1
  16.         mov     dx,80H
  17.         int     13H
  18.  
  19.         mov     si,OFFSET BUF + 1BEH
  20.         mov     di,OFFSET PTABLE
  21.         mov     cx,40H
  22.         rep     movsb           ;move partition table to new sector
  23.  
  24.         mov     ax,301H         ;and write it to disk
  25.         mov     bx,OFFSET BOOT
  26.         mov     cx,1
  27.         int     13H
  28.  
  29.         mov     ax,4C00H        ;then exit to DOS
  30.         int     21H
  31.  
  32. BUF:                            ;area for reading disk
  33.  
  34.  
  35.  
  36. ;The Master Boot Sector starts here.
  37.  
  38.         ORG     7C00H
  39.  
  40. BOOT:
  41.         cli
  42.         xor     ax,ax           ;set up segments and stack
  43.         mov     ds,ax
  44.         mov     es,ax
  45.         mov     ss,ax
  46.         mov     sp,OFFSET BOOT
  47.         sti
  48.  
  49.         mov     si,OFFSET PTABLE;find active partition
  50.         mov     cx,4
  51. SRCH:   lodsb
  52.         cmp     al,80H
  53.         je      ACT_FOUND
  54.         add     si,0FH
  55.         loop    SRCH
  56.         mov     si,OFFSET NO_OP ;no operating system found
  57. ERROR:  call    DISP_STRING     ;display error message
  58.         int     18H             ;and try "basic loader"
  59.  
  60. ACT_FOUND:
  61.         mov     dl,al           ;operating system found
  62.         lodsb                   ;set up registers to read its boot sector
  63.         mov     dh,al
  64.         lodsw
  65.         mov     cx,ax
  66.         mov     bx,OFFSET BOOT
  67.         mov     ax,201H
  68.  
  69.         push    cx              ;move the mbr to offset 600H first!
  70.         mov     si,bx
  71.         mov     di,600H
  72.         mov     cx,100H
  73.         rep     movsw
  74.         pop     cx
  75.         mov     si,OFFSET MOVED - 7C00H + 600H
  76.         push    si
  77.         ret                     ;and jump there
  78.  
  79. MOVED:  int     13H             ;load the boot sector
  80.         mov     si,OFFSET NO_RD
  81.         jc      ERROR           ;display message if it can't be read
  82.         mov     ax,OFFSET BOOT
  83.         push    ax
  84.         ret                     ;jump to operating system boot sector
  85.  
  86.  
  87. ;This displays the asciiz string at ds:si.
  88. DISP_STRING:
  89.         lodsb
  90.         or      al,al
  91.         jz      DSR
  92.         mov     ah,0EH
  93.         int     10H
  94. DSR:    ret
  95.  
  96. NO_OP   DB      'No operating system.',0
  97. NO_RD   DB      'Cannot load operating system.',0
  98.  
  99.         ORG     7DBEH
  100.  
  101. PTABLE  DB      40H dup (?)     ;Here is the partition table
  102.  
  103.         DB      55H,0AAH
  104.  
  105.         END     LOADER
  106.